package com.jvtd.eyl.ui.splash;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.jvtd.eyl.R;
import com.jvtd.eyl.base.BaseMvpActivity;
import com.jvtd.eyl.ui.guide.GuideActivity;
import com.jvtd.eyl.ui.main.MainActivity;

import javax.inject.Inject;

import butterknife.BindView;

public class SplashActivity extends BaseMvpActivity implements SplashMvpView {
    @Inject
    SplashPresenter<SplashMvpView> mPresenter;

    @BindView(R.id.frame_layout)
    View mRootLayout;

    public static Intent getIntent(Context context) {
        return new Intent(context, SplashActivity.class);
    }

    @Override
    protected void getLayout() {
        setContentView(R.layout.jvtd_activity_frame_layout);
    }

    @Override
    protected void initViewAndData() {
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected void onViewCreated(Bundle savedInstanceState) {
        super.onViewCreated(savedInstanceState);
        //检测权限
        checkStoragePermission();
    }

    /**
     * 权限通过
     */
    @Override
    protected void onGranted() {
        super.onGranted();
        mRootLayout.postDelayed(() -> mPresenter.onAttach(SplashActivity.this), 1500);
    }

  @Override
  public void openGuideActivity()
  {
    //引导页
    Intent intent = GuideActivity.getIntent(SplashActivity.this);
    openActivity(intent);
  }

//  @Override
//  public void openLoginActivity()
//  {
//    //登录
//    Intent intent = LoginActivity.getIntent(SplashActivity.this);
//    openActivity(intent);
//  }

    @Override
    public void openMainActivity() {
        //MainActivity
        Intent intent = MainActivity.getIntent(SplashActivity.this);
        openActivity(intent);
    }

    private void openActivity(Intent intent) {
        startActivity(intent);
        finish();
        overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out);
    }

    @Override
    protected void onDestroy() {
        mPresenter.onDetach();
        super.onDestroy();
    }
}
